package com.zyd.module.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zyd.common.util.Pagination;
import com.zyd.enums.GlobalConstant;
import com.zyd.module.admin.mapper.CustomerMapper;
import com.zyd.module.admin.model.CustomerEntity;
import com.zyd.module.admin.model.PictureRoundEntity;
import com.zyd.module.admin.service.CustomerService;
import com.zyd.module.api.vo.CustomerVo;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;


/**
 * @author tiezhu
 * @date 2022年4月6日
 */
@Service("customerService")
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, CustomerEntity> implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public IPage<CustomerEntity> pageCustomerList(CustomerVo customerVo, Integer pageNumber, Integer pageSize) {
        QueryWrapper<CustomerEntity> queryWrapper=new QueryWrapper<>();
        if (customerVo.getCusName()!=null&&!"".equals(customerVo.getCusName())){
            queryWrapper.like("cus_name",customerVo.getCusName());
        }
        if (customerVo.getAddress()!=null&&!"".equals(customerVo.getAddress())){
            queryWrapper.like("address",customerVo.getAddress());
        }
        if (customerVo.getProName()!=null&&!"".equals(customerVo.getProName())){
            queryWrapper.like("pro_name",customerVo.getProName());
        }
        queryWrapper.eq("del_flag",1);
        queryWrapper.orderByDesc("create_time");
        IPage<CustomerEntity> page = new Pagination<>(pageNumber, pageSize);
        IPage<CustomerEntity> entityIPage = customerMapper.selectPage(page, queryWrapper);
        return entityIPage;
    }

    @Override
    public Integer removeCustomerByIds(List<String> asList) {
        UpdateWrapper<CustomerEntity> updateWrapper=new UpdateWrapper<>();
        updateWrapper.in("id",asList);
        CustomerEntity entity=new CustomerEntity();
        entity.setDelFlag(GlobalConstant.CUSTOMER_DEL);
        return customerMapper.update(entity, updateWrapper);
    }
}